package kayao.client.network.message;

import kayao.client.data.SharedMemory;
import kayao.common.KayaoValues;
import kayao.common.NetworkUtils;

public class LogOutMessage extends Message {

	private static final int RETRIES = 0;
	private static final int TIMEOUT_LENGTH_MILLIS = 0;
	private static final int PRIORITY = PRIORITY_LOW;

	public LogOutMessage(String targetAddress) {
		super(targetAddress, RETRIES, TIMEOUT_LENGTH_MILLIS, PRIORITY);
		createPacketData();
	}

	@Override
	public String type() {
		// TODO Auto-generated method stub
		return "Logout";
	}
	public void createPacketData() {
		// [magic-nr 4 | msg-id 1 | msg-counter 4 | client-id 4] = 13
		mSendData = new byte[13];
		int index = 0;
		// Insert magic number
		NetworkUtils.insertIntToByteArray(mSendData, index, KayaoValues.MAGIC_NUMBER);
		index += 4;
		// Insert message id
		mSendData[index] = KayaoValues.LOGOUT_MSG;
		index += 1;
		//Insert the message counter
		NetworkUtils.insertIntToByteArray(mSendData, index, mMessageId);
		index += 4;
		// Insert local client id
		NetworkUtils.insertIntToByteArray(mSendData, index, SharedMemory.getInstance().getLocalId());
		index += 4;
	}

}
